package MainPackage;

import StackPackage.Stack;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by thoughtworks on 17/7/14.
 */
public class Test
{
    public static void main(String[] args)
    {
        Stack s = new Stack();
        char c = 1;
        while(c != '0')
        {
            System.out.println("1. Push to stack\n2. Pop from stack\n3. Display stack\n0. Exit");
            c = readCharacter();
            switch (c)
            {
                case '1':
                    System.out.print("Enter number : ");
                    char i = readCharacter();
                    s.push(i);
                    break;
                case '2':
                    System.out.println("Popped " + s.pop());
                    break;
                case '3':
                    System.out.println("Stack contents : ");
                    s.printStack();
                    break;
            }
        }
    }

    private static char readCharacter() {
        BufferedReader b;
        InputStreamReader i = new InputStreamReader(System.in);
        b = new BufferedReader(i);
        try {
            return (char) b.read();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
        return 0;
    }
}
